﻿#region 命名空间

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Sharp.DataTransferObject;
using Sharp.Portal.Mvc;
using Sharp.Portal;
using Sharp.Portal.AdminLTE;
using Sharp.Portal.Mvc.Form;
using Sharp.Portal.Other;
using Sharp.Portal.Mvc.List;

#endregion

namespace Sharp.WebBooter.Areas.Platform.Models
{
    /// <summary>
    /// 用户管理
    /// </summary>
    [ModuleCode("UserManage"), Title("用户管理"), ModuleItem(typeof(UserViewModel))]
    [DataHandler(ModuleOP.Details, "浏览", 0)]
    [DataHandler(ModuleOP.Create, "新增", 1)]
    [DataHandler(ModuleOP.Edit, "修改", 2)]
    [DataHandler(ModuleOP.Delete, "删除", 3)]
    [DataHandler("Roles", "角色", 4, OnClientClick = "new User().ShowRoleWindow();", Icon = "fa fa-paragraph")]
    [DataHandler("File", "档案", 5, OnClientClick = "new User().File();", Icon = "fa fa-user")]
    public class UserIndexViewModel : BSSharpList
    {
        public UserIndexViewModel()
        {
            this.Feature = ListFeature.MultiSelect | ListFeature.Paging | ListFeature.RowNumber;
            this.ImportJavascript = "~/Areas/Platform/Scripts/User.js";
            this.IsUseOrgTreeLayout = true;
        }
        /// <summary>
        /// 自定义查询面板
        /// </summary>
        protected override void InitQueryPanel()
        {
            base.InitQueryPanel();
            var helper = new SharpListHelper<UserIndexViewModel>(this);
            helper.AddQueryItem(x => x.Roles).Text("角色")
                .SearchFor("Roles.Id").ValueField("Id").DisplayField("Name");
            this.QueryItems.Add(new QueryItem()
            {
                Name = "OrgId",
                SearchFor = "Person.OrgId",
                IsHiddenField = true,
                ValueFrom = QueryItem.ValueFromType.DefaultValue
            });
        }


        [Column(Hidden = true)]
        public int Id { get; set; }
        /// <summary>
        /// 获取或设置当前客户的用户名。
        /// </summary>
        [Column(Width = 100, Text = "用户名"), QueryOption(Option = QueryFeature.DefualtQuery)]
        public string UserName { get; set; }


        /// <summary>
        /// 获取或设置当前客户的电子邮件地址。
        /// </summary>
        [Column(Width = 100, Text = "电子邮件")]
        public string Email { get; set; }

        /// <summary>
        /// 获取或设置用户账户注册的时间。
        /// </summary>
        [DateColumn(Width = 108, Text = "注册时间", DataIndex = "profile.registeredTime",Format ="YYYY-MM-DD HH:mm:ss")]
        public DateTime RegisteredTime { get; set; }

        /// <summary>
        /// 获取或设置用户账户最后一次登录的时间。
        /// </summary>
        [DateColumn(Width = 108, Text = "最后登录", Format = "YYYY-MM-DD HH:mm:ss")]
        public DateTime? LastLogonTime { get; set; }
        /// <summary>
        /// 获取或设置用户最后一次登录的IP
        /// </summary>
        [Column(Width = 100, Text = "最后IP")]
        public string LastLogonIp { get; set; }

        /// <summary>
        /// 获取一个值，该值指示成员资格用户是否因被锁定而无法进行验证。
        /// </summary>
        [BooleanColumn(Width = 100, Text = "是否被锁定", TrueText = "锁定", FalseText = "正常", Align = Alignment.Center, DataIndex = "profile.isLockedOut")]
        public bool IsLockedOut { get; set; }

        /// <summary>
        /// 是否审核
        /// </summary>
        [BooleanColumn(Width = 100, Text = "是否审核", TrueText = "审核", FalseText = "未审核", Align = Alignment.Center, DataIndex = "profile.isApproved")]
        public bool IsApproved { get; set; }
        /// <summary>
        /// 角色
        /// </summary>
        [CustomField(FieldType.DropDownList, "Name", "Id", nameof(Roles))]
        public IEnumerable<RoleDTO> Roles { get; set; }


    }
}